# -*- coding:utf-8 -*-
#
"""
  用enumerate将string中的1都找出来,
  用enumerate实现：
"""


def position_feature(str):
    # str=[0,1,0,0,0,0,1,0,0,0]
    #onePos = []
    z = []
    cmax=[]
    d=[]
    allPos = list(((pos, val) for pos, val in enumerate(str) if val == 1 or val == 0))
    onePos = list(((pos, val) for pos, val in enumerate(str) if val == 1))
    #zeroPos = list(((pos, val) for pos, val in enumerate(str) if val == 0))
    # print onePos
    # print zeroPos
    for i in range(len(allPos)):
        o = allPos[i][0]
        z.append(o)
    # print z
    c1 = onePos[0][0]
    c2 = onePos[1][0]


    for i in range(len(allPos)):

        #d3=[d1,d2]

        d1 = z[i] - c1  # 句子中的词到第一个实体的距离

        d2 = z[i] - c2  # 句子中的词到第二个实体的距离
        d.append(d1)
        d.append(d2)




    #print c2-c1

    return d,c1,c2
def entity_distance(str):
    onePos = list(((pos, val) for pos, val in enumerate(str) if val == 1))
    c1 = onePos[0][0]
    c2 = onePos[1][0]
    rlen = c2 - c1 + 1
    return rlen







